// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import iView from 'iview'
import ElementUI from "element-ui"
// import './iview/dist/styles/iview.css'
// import 'element-ui/lib/theme-default/index.css'
// import 'bootstrap/dist/css/bootstrap.css'
// import './assets/css/icon/font-awesome-4.7.0/css/font-awesome.min.css'
// import './assets/css/icon/ionicons-2.0.1/css/ionicons.min.css'
// import './assets/css/AdminLTE.css'
// import './assets/css/skins/_all-skins.css'
import {doGet} from "./assets/js/utils/RequestUtils"
import {LOGIN, LOGOUT} from "./store/mutationTypes"

import './css/app.css'

Vue.config.productionTip = false;
Vue.use(ElementUI);
Vue.use(iView);
/* 给promise注册一个finally方法 */
// Promise.prototype.finally = function (callback) {
//   let P = this.constructor;
//   return this.then(
//     value => P.resolve(callback()).then(() => value),
//     reason => P.resolve(callback()).then(() => {
//       throw reason
//     })
//   );
// };

/* 加载VUE框架 */
new Vue({
  el: '#app',
  router,
  store,
  template: '<App/>',
  components: {App},
  methods: {
    //开局检查是否需要重新登录
    checkCurrentUser() {
      doGet("/user/check", {component: this})
        .then(response => {
          if (response.status === "SUCCESS") {
            //设置当前用户以及登入状态，同时将页面跳转至首页
            this.$store.commit(LOGIN, response);
            this.$router.replace("/");
          } else {
            //设置登出状态
            this.$store.commit(LOGOUT);
            this.$router.push("/login")
          }
        });
    },
    //配置加载进度条
    configLoadingBar() {
      this.$Loading.config({
        color: '#5cb85c',
        height: 5
      });
    }
  },
  created() {
    this.checkCurrentUser();
    this.configLoadingBar();
  }
});


// WEBPACK FOOTER //
// ./src/main.js
